package org.repchain;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @author lhc
 * @version 1.0
 * @className FakeElectric
 * @date 2021年10月28日 9:53 上午
 * @description 描述
 */
public class FakeElectric {

    public static void main(String[] args) throws Exception{
        while (true) {
            String shell1 = "java -jar /Volumes/DATA/ideaProject/hcframe/upload-electric/target/test/uploadElectric-1.0-SNAPSHOT.jar consume 68A0A1A2A3A4A56891050000000001FF9116";
            shell(shell1);
            String shell2 = "java -jar /Volumes/DATA/ideaProject/hcframe/upload-electric/target/uploadElectric-1.0-SNAPSHOT.jar produce 68A0A1A2A3A4A56891050000000001FF9116";
            shell(shell2);
            try {
                Thread.sleep(30*1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void shell(String shell) {
        try {
            Process process = Runtime.getRuntime().exec(shell);
            int exitValue = process.waitFor();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()), 1024);
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                System.out.println(line);
            }
            if (0 != exitValue) {
                System.err.println("call shell failed. error code is :" + exitValue);
            }
        } catch (Throwable e) {
            System.err.println("call shell failed. " + e);
        }
    }
}
